<?xml version="1.0" encoding="UTF-8"?>
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.prime.com.tr/ui">
    <ui:composition template="/view/template.xhtml">
        <ui:define name="head">
            <script type="text/javascript">
                    function handleConfirmRequest(xhr, status, args) {
                            if(args.success) {
                                    orderCommdoityDialog.hide();
                            } 
                    }

                      function handleStockOutRequest(xhr, status, args){
                             if(args.success) {
                                    orderCommdoityDialog.show();
                            }
                     }
            </script>
        </ui:define>
        <ui:define name="content">
            <f:view>
                <h:form id ="form1">
                    <p:dataTable value="#{purchaseManager.purchaseFormList}" var="item" id="purchaseForms" paginator="true" rows="20"
                                 selectionMode="single" selection="#{purchaseManager.selectedPurchaseForm}"
                                 update="form2:display,form2:purchaseForms" onselectComplete="purchaseFormDialog.show()">
                        <f:facet name="header">
                            <h:panelGrid columns="2">
                                <p:breadCrumb preview="true" expandEffectDuration="200" previewWidth="20" style="width: 500px" expandedBeginningItems="1" expandedEndItems="0">
                                    <p:menuitem value="选项"/>
                                    <p:menuitem value="新增采购单" actionListener="#{purchaseManager.create}" update="form1:purchaseForms"/>
                                    <p:menuitem value="查询未结算单" actionListener="#{purchaseManager.findUnSettledForms}" update="form1:purchaseForms"/>
                                </p:breadCrumb>
                                <h:panelGrid columns="4" style="width: 300px">
                                    <h:outputLabel value="模糊查询"></h:outputLabel>
                                    <h:inputText value="#{purchaseManager.searchContent}" title="可输入部分单号,男宾或女宾的姓名与电话进行查询"></h:inputText>
                                    <p:commandLink update="form1:purchaseForms" actionListener="#{purchaseManager.search}" title="查询">
                                        <p:graphicImage value="/resources/images/search.png"/>
                                    </p:commandLink>
                                    <p:ajaxStatus  style="width:16px;height:16px;">
                                        <f:facet name="start">
                                            <h:graphicImage  value="/resources/images/ajaxloading.gif" />
                                        </f:facet>
                                        <f:facet name="complete">
                                            <h:outputText value=""/>
                                        </f:facet>
                                    </p:ajaxStatus>
                                </h:panelGrid>
                            </h:panelGrid>
                        </f:facet>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="序号"/>
                            </f:facet>
                            <h:outputText value="#{item.number}"/>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value=""/>
                            </f:facet>
                            <h:selectBooleanCheckbox value="#{item.cancelled}" disabled="true"/>
                        </p:column>

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="是否结算"/>
                            </f:facet>
                            <h:selectBooleanCheckbox value="#{item.settled}" disabled="true"/>
                        </p:column>


                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="结算时间"/>
                            </f:facet>
                            <h:outputText value="#{item.settledTime}">
                                <f:convertDateTime pattern="MM/dd/yyyy" />
                            </h:outputText>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="总计"/>
                            </f:facet>
                            <h:outputText value="#{item.totalAmount}">
                                <f:convertDateTime pattern="yyyy/MM/dd" />
                            </h:outputText>
                        </p:column>
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="付款"/>
                            </f:facet>
                            <h:outputText value="#{item.totalExpense}">
                                <f:convertDateTime pattern="yyyy/MM/dd" />
                            </h:outputText>
                        </p:column>

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="退款"/>
                            </f:facet>
                            <h:outputText value="#{item.totalPayment}">
                                <f:convertDateTime pattern="yyyy/MM/dd" />
                            </h:outputText>
                        </p:column>

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="创建时间"/>
                            </f:facet>
                            <h:outputText value="#{item.createdTime}">
                                <f:convertDateTime pattern="yyyy/MM/dd" />
                            </h:outputText>
                        </p:column>
                    </p:dataTable>
                </h:form>

                <p:dialog header="采购单明细" widgetVar="purchaseFormDialog"
                          modal="true" draggable="false" width="1020" closeListener="#{purchaseManager.cancellCreate}" resizable="false">
                    <p:layout  style="width:1000px;height:600px;">
                        <p:layoutUnit position="center" resizable="false" width="700">
                            <h:form id="form2" >
                                <h:panelGrid  id="display">
                                    <h:panelGrid columns="6"  columnClasses="column1,column2,column1,column2,column1,column2">
                                        <h:outputLabel value="单号:" for="number" />
                                        <h:outputLabel id="number" value="#{purchaseManager.selectedPurchaseForm.number}" title="number" />
                                        <h:outputLabel value="开单人:" for="createdBy" />
                                        <h:inputText id="createdBy" value="#{purchaseManager.selectedPurchaseForm.createdBy.name}" title="createdBy"  disabled="true"/>
                                        <h:outputLabel value="开单时间:" for="createdTime" />
                                        <h:inputText id="createdTime" value="#{purchaseManager.selectedPurchaseForm.createdTime}" title="createdTime"  disabled="true"/>
                                        <h:outputLabel value="取消" for="cancelled" />
                                        <h:selectBooleanCheckbox id="cancelled" value="#{purchaseManager.selectedPurchaseForm.cancelled}" disabled="true"/>
                                        <h:outputLabel value="总计:" for="totalAmount" />
                                        <h:inputText id="totalAmount" value="#{purchaseManager.selectedPurchaseForm.totalAmount}" title="totalAmount" disabled="true"/>
                                        <h:outputLabel value="已付款:" for="totalExpense" />
                                        <h:inputText id="totalExpense" value="#{purchaseManager.selectedPurchaseForm.totalExpense}" title="totalExpense" disabled="true"/>
                                        <h:outputLabel value="已退库:" for="totalPayment" />
                                        <h:inputText id="totalPayment" value="#{purchaseManager.selectedPurchaseForm.totalPayment}" title="totalPayment" disabled="true"/>
                                    </h:panelGrid>
                                    <p:dataTable id="purchaseRecords" value="#{purchaseManager.selectedPurchaseForm.purchaseRecordCollection}" var="item" rowIndexVar="rowIndex">

                                        <p:column>
                                            <f:facet name="header">
                                                <h:outputText value="序号"/>
                                            </f:facet>
                                            <h:outputText value="#{rowIndex}"/>
                                        </p:column>
                                        <p:column>
                                            <f:facet name="header">
                                                <h:outputText value="编码"/>
                                            </f:facet>
                                            <h:outputText value="#{item.number}"/>
                                        </p:column>
                                        <p:column>
                                            <f:facet name="header">
                                                <h:outputText value="名称"/>
                                            </f:facet>
                                            <h:outputText value="#{item.name}"/>
                                        </p:column>
                                        <p:column>
                                            <f:facet name="header">
                                                <h:outputText value="单价"/>
                                            </f:facet>
                                            <h:outputText value="#{item.unitCost}"/>
                                        </p:column>
                                        <p:column>
                                            <f:facet name="header">
                                                <h:outputText value="数量"/>
                                            </f:facet>
                                            <h:inputText value="#{item.quantity}" size="3"/>
                                        </p:column>
                                        <p:column>
                                            <f:facet name="header">
                                                <h:outputText value="入库数量"/>
                                            </f:facet>
                                            <h:outputText value="#{item.stockin}" />
                                        </p:column>

                                        <p:column>
                                            <f:facet name="header">
                                                <h:outputText value="退货数量"/>
                                            </f:facet>
                                            <h:inputText value="#{item.returnedQuantity}" size="3"/>
                                        </p:column>
                                        <p:column headerText="选项">
                                            <p:commandLink title="入库" action="#{orderManager.stockOut(item,false)}" oncomplete="handleStockOutRequest(xhr, status, args)" update="form3:display,form:growl" >
                                                <p:graphicImage value="/resources/images/upload.png"/>
                                            </p:commandLink>
                                            <p:commandLink title="退货" action="#{orderManager.stockOut(item,true)}" oncomplete="handleStockOutRequest(xhr, status, args)" update="form3:display,form:growl" >
                                                <p:graphicImage value="/resources/images/download.gif"/>
                                            </p:commandLink>
                                        </p:column>
                                    </p:dataTable>
                                    <f:facet name="footer">
                                        <h:panelGroup>
                                            <p:commandButton  value="保存" actionListener="#{orderManager.save}"  update="form1:orders,form:growl,form3:accounts" oncomplete="handleSaveRequest(xhr, status, args)"></p:commandButton>
                                        </h:panelGroup>
                                    </f:facet>
                                </h:panelGrid>
                            </h:form>
                        </p:layoutUnit>

                        <p:layoutUnit position="right"  resizable="false" style="font-size: 75%" width="300">
                            <h:form id="form4">
                                <h:panelGroup>
                                    <p:dataTable id="selectedCommodities" value="#{commodityManager.commodityListForSelection}" var="item" rowIndexVar="rowIndex">
                                        <f:facet name="header">
                                            <h:panelGrid columns="2">
                                                <h:selectOneMenu value="#{commodityManager.commodityProperty}" id="commodityPropertyMenu">
                                                    <f:selectItems value="#{applicationBean.retailMaterialCommodityPropertyItems}"></f:selectItems>
                                                    <p:ajax  update="form4:selectedCommodities,form4:selectedCommodityTypes" listener="#{commodityManager.searchByPropertyForSelection}" />
                                                </h:selectOneMenu>
                                                <h:selectOneMenu id="selectedCommodityTypes" value="#{commodityManager.commodityType}">
                                                    <f:selectItems value="#{commodityManager.commodityTypeItems}"></f:selectItems>
                                                    <p:ajax  update="form4:selectedCommodities" listener="#{commodityManager.searchByTypeForSelection}" />
                                                </h:selectOneMenu>
                                            </h:panelGrid>
                                        </f:facet>

                                        <p:column>
                                            <f:facet name="header">
                                                <h:outputText value="名称"/>
                                            </f:facet>
                                            <h:outputText value="#{item.name}"/>
                                        </p:column>
                                        <p:column >
                                            <f:facet name="header">
                                                <h:outputText value="编码"/>
                                            </f:facet>
                                            <h:outputText value="#{item.number}"/>
                                        </p:column>
                                        <p:column  >
                                            <f:facet name="header">
                                                <h:outputText value="单价"/>
                                            </f:facet>
                                            <h:outputText value="#{item.uitPrice}"/>
                                        </p:column>
                                        <p:column headerText="添加">
                                            <p:commandLink action="#{orderManager.addMaterial(item)}" title="添加" update="form:growl,form5:workingOrderCommodities" oncomplete="handleAddMaterial(xhr, status, args)" >
                                                <p:graphicImage value="/resources/images/edit.png"/>
                                            </p:commandLink>
                                        </p:column>
                                    </p:dataTable>
                                </h:panelGroup>
                            </h:form>
                        </p:layoutUnit>
                    </p:layout>
                </p:dialog>
                <p:dialog widgetVar="orderCommdoityDialog" modal="true" width="300" header="出入库">
                    <h:form id="form3">
                        <h:panelGrid columns="2" id ="display">
                            <h:outputLabel value="商品编号:"  />
                            <h:outputLabel  value="#{orderManager.inventoryRecord.orderCommodity.number}" title="number" />
                            <h:outputLabel value="商品名称:" />
                            <h:outputLabel  value="#{orderManager.inventoryRecord.orderCommodity.name}" title="name" />
                            <h:outputLabel value="已出库数量:"  />
                            <h:outputLabel id="stockOutNumber" value="#{orderManager.inventoryRecord.orderCommodity.stockout}" title="已出库数量"/>
                            <h:outputLabel value="库存数量:"/>
                            <h:outputLabel value="#{orderManager.inventoryRecord.commodity.stocks}" title="库存数量"/>
                            <h:outputLabel value="#{orderManager.stockQuantityLabel}" for="quantity" />
                            <h:inputText id="quantity" value="#{orderManager.inventoryRecord.quantity}" title="出库数量"/>
                            <f:facet name="footer">
                                <h:panelGroup>
                                    <p:commandButton  value="确认" actionListener="#{orderManager.confirmStockOut}"  update="form2:orderCommodities,form:growl" oncomplete="handleConfirmRequest(xhr, status, args)"></p:commandButton>
                                </h:panelGroup>
                            </f:facet>
                        </h:panelGrid>
                    </h:form>
                </p:dialog>
            </f:view>
        </ui:define>
    </ui:composition>
</html>
